import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
// 数据初始值
let state = {
  token: null, // 登陆后服务器返回的标记
  title: null, // 界面标题
  price: null, // 产品单价
  recipient: { // 收货信息
    user: null, // 收货人姓名
    provinceid: null, // 收货人省份
    cityid: null, // 收货人市区
    address: null, // 收货人地址
    phone: null // 收货人电话
  },
  user: {}, // 登陆用户信息
  tab: 'product' // 当前tab
}

const mutations = {
  setToken (state, amount) { // 设置标记
    state.token = amount
  },
  setTitle (state, amount) { // 设置标题内容
    state.title = amount
  },
  setAddress (state, amount) { // 设置订单收货地址
    state.recipient = amount
  },
  setUser (state, amount) { // 设置登录用户信息
    state.user = amount
  },
  setPrice (state, amount) { // 设置产品单价
    state.price = amount
  },
  setTab (state, amount) { // 设置产品单价
    state.tab = amount
  }
}

const actions = {
  setToken ({commit, state}, data) { // 设置标记
    commit('setToken', data)
  },
  setTitle ({commit, state}, data) { // 设置标题内容
    commit('setTitle', data)
  },
  setAddress ({commit, state}, data) { // 设置订单收货地址
    commit('setAddress', data)
  },
  setUser ({commit, state}, data) { // 设置用户信息
    commit('setUser', data)
  },
  setPrice ({commit, state}, data) { // 设置产品单价
    commit('setPrice', data)
  },
  setTab ({commit, state}, data) { // 设置tab
    commit('setTab', data)
  }
}

const getters = {
  getToken: (state) => { // 获取标记
    return state.token
  },
  getTitle: (state) => { // 获取标题内容
    return state.title
  },
  getUser: (state) => { // 获取用户信息
    return state.user
  },
  getPrice: (state) => { // 获取产品单价
    return state.price
  },
  setTab: (state) => { // 设置tab
    return state.tab
  }
}

export default new Vuex.Store({
  state,
  mutations,
  actions,
  getters
})
